package io.oschina.binv.kapp.fragment

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView

import io.oschina.binv.kapp.R
import io.oschina.binv.kapp.framework.BaseFragment
import io.oschina.binv.kapp.framework.ReuseActivity


/**
 * create an instance of this fragment.
 */
class FirstFragment : BaseFragment() {
    override fun setContentView(inflater: LayoutInflater, container: ViewGroup?): View {
       return inflater.inflate(R.layout.fragment_first, container, false)
    }

    companion object {
        val TITLE = "TITLE"
        val ICONID="ICONID"
        val PAYLOAD="PAYLOAD"
    }
    override fun initViewsAndLocalData(savedBundle: Bundle): (outBundle: Bundle) -> Unit {
        if (arguments != null) {
            val title=arguments.getString(TITLE,"")
            val content=arguments.getString(PAYLOAD,"")
            findViewById<TextView>(R.id.tv_title).apply {
                text=title
            }

            findViewById<TextView>(R.id.tv_content).apply {
                text = content
            }
            findViewById<Button>(R.id.btn_new).setOnClickListener { _->
                    val intent= Intent(activity, ReuseActivity::class.java).apply {
                        putExtra(ReuseActivity.FRAGMENT_NAME, FirstFragment::class.java.canonicalName)
                        putExtra(ReuseActivity.FRAGMENT_ARGS, Bundle().apply {
                            putString(FirstFragment.TITLE, title + "+")
                            putString(FirstFragment.PAYLOAD, content + "+")
                        })
                    }
                    startActivity(intent)
                }
            }
//        view.findViewById<Button>(R.id.btn_radio).setOnClickListener { _ ->
//            RxGalleryFactory.radio(activity,true).subscribe(object : RxBusResultDisposable<ImageCropRadioResultEvent>() {
//                override fun onEvent(imageCropRadioResultEvent: ImageCropRadioResultEvent) {
//                    val cmp=imageCropRadioResultEvent.result.compressImagePath(context)
//                    Toast.makeText(activity, "裁剪的图片路径：" + cmp.absoluteFile, Toast.LENGTH_SHORT).show()
//                }
//            }).openGallery()
//        }
//        view.findViewById<Button>(R.id.btn_multiple).setOnClickListener { _ ->
//            RxGalleryFactory.multiple(activity,5).subscribe(object : RxBusResultDisposable<ImageMultipleResultEvent>() {
//                override fun onEvent(imageMultipleResultEvent: ImageMultipleResultEvent) {
//                    val cmp=imageMultipleResultEvent.result[0].compressImagePath(context)
//                    Toast.makeText(activity, "已选择" + cmp.absoluteFile + "张图片", Toast.LENGTH_SHORT).show()
//                }
//            }).openGallery()
//        }
        return {}
    }

    override fun loadRemoteData() {

    }


}
